﻿/*
 * Interação Sistemas - iNotifications 0.0.1 - jQuery Plugin
 * http://www.interacaosistemas.com.br/blog
 * Copyright (c) 2012 Roger Medeiros
 * Microsoft Reciprocal License (Ms-RL)
 * Revision: $Id: jquery.inotifications.js 1 2012-07-18
 */
;(function ( $, window, undefined ) {
	var pluginName = 'iNotifications',
		document = window.document,
		loaded = false;
		defaults = {
			version: "0.0.1"
		};

	var methods = {
		show : function( method, options ) {
			var markup = [
				'<div class="inotifications-note">',
				'\t<div class="inotifications-header"><span>', options.title, '</span></div>',
				'\t<div class="inotifications-close" onclick="$(this.parentNode).iNotifications(' + "'" + 'hide' + "'" + ');"><span>X</span></div>',
				'\t<div class="inotifications-message">', options.msg, '</div>',
				'</div>'
			].join('');
			
			$(markup).hide().appendTo(this.element).fadeIn();
		},
		hide : function (method, options) {
			$(this.element).fadeOut(300);
		}
	};

	function iNotifications( element, method, options ) {
		this.element = element;
		this.options = $.extend( {}, defaults, options) ;
		this._defaults = defaults;
		this._name = pluginName;
		
		if ( methods[method] ) {
			return methods[method].apply(this, Array.prototype.slice.call( arguments, 1 ));
		} else if ( typeof method === 'object' || ! method ) {
			return methods.init.apply( this, arguments );
		} else {
			$.error( 'Method ' +  method + ' does not exist on jQuery.iNotifications' );
		}		
	}
	
	$.fn[pluginName] = function ( method, options ) {
		return this.each(function () {
			if (!$.data(this, 'plugin_' + pluginName)) {
				$.data(this, 'plugin_' + pluginName, new iNotifications( this, method, options ));
			} else {
				iNotifications( this, method, options );
			}
		});
	}
}(jQuery, window));